package com.goudan.rabbitmq.demo.util;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

public class RabbitMqUtils {
    // 得到一个连接的 channel
    public static Channel getChannel() throws Exception {
        // 创建一个连接工厂
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("10.231.34.231");
        factory.setPort(5672);
        factory.setUsername("longfor-member-sit");
        factory.setPassword("aQuBoYOUr9fxgs");
        factory.setVirtualHost("longfor-member-sit");
        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();
        return channel;
    }
    public static Channel getLocalChannel() throws Exception {
        // 创建一个连接工厂
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("127.0.0.1");
        factory.setPort(5672);
        factory.setUsername("guest");
        factory.setPassword("guest");
        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();
        return channel;
    }
}
